package com.hualan.sfzy.controller.course;

import com.hualan.sfzy.entity.CourseComment;
import com.hualan.sfzy.service.course.CourseCommentService;
import com.hualan.sfzy.utils.Result;
import com.hualan.sfzy.vo.CourseCommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseComment")
public class CourseCommentController {
    @Autowired
    private CourseCommentService courseCommentService;

    @PostMapping
    public Result add(@RequestBody CourseComment courseComment){
        int result = courseCommentService.add(courseComment);
        if(result>0)
            return Result.success(result);
        return Result.error("评论添加失败");
    }
    @GetMapping
    public Result find(){
        List<CourseComment> courseOrders = courseCommentService.find();
        if(courseOrders!=null)
            return Result.success(courseOrders);
        return Result.error("评论查询失败");
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        CourseComment courseComment = courseCommentService.findById(id);
        if(courseComment!=null)
            return Result.success(courseComment);
        return Result.error("评论查询失败");
    }
    @PostMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestBody(required = false) CourseCommentVo courseCommentVo){
        return Result.success(courseCommentService.findPage(pageNum,pageSize,courseCommentVo));
    }
    @PutMapping
    public Result edit(@RequestBody CourseComment courseComment){
        int result = courseCommentService.edit(courseComment);
        if(result>0)
            return Result.success(result);
        return Result.error("评论修改失败");
    }
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Integer id){
        return Result.success(courseCommentService.remove(id));
    }
    @DeleteMapping("/batch")
    public Result removeBatch(Integer[] ids){
        System.out.println(ids);
        return Result.success(courseCommentService.removeBatch(ids));
    }

}
